package model.input;

import java.awt.event.KeyEvent;

import model.GameContext;
import model.characters.CharacterInterface;

public class PhaseKeyboardHandler implements KeyboardHandler{

	private CharacterInterface player;

	@Override
	public void keyTyped(KeyEvent e) {
	}

	@Override
	public void keyReleased(KeyEvent e) {
		switch (e.getKeyCode()) {
		case KeySettings.RIGHT:
			player.setRightDirection(GameContext.NULL_DIRECTION);
			player.setDirection(player.getLeftDirection()+player.getRightDirection());
			player.setWalkingR(false);
			break;
		case KeySettings.LEFT:
			player.setLeftDirection(GameContext.NULL_DIRECTION);
			player.setDirection(player.getLeftDirection()+player.getRightDirection());
			player.setWalkingL(false);
			break;
		case KeySettings.RUN:
			player.setRunning(false);
			break;
		case KeySettings.JUMP:
			if(!player.isShooting())
				player.setJumping(true);
			break;
//		case KeySettings.SHOT:
//			player.setShooting(false);
//			break;
		case KeySettings.TURNDOWN:
			player.turnUp();
			player.setLowered(false);
			break;
		default:
			break;
		}
	}

	@Override
	public void keyPressed(KeyEvent e) {

		switch (e.getKeyCode()) {
		case KeySettings.RIGHT:
			player.setRightDirection(GameContext.RIGHT_DIRECTION);
			player.setDirection(GameContext.RIGHT_DIRECTION);
			player.setWalkingR(true);
			break;
		case KeySettings.LEFT:
			player.setLeftDirection(GameContext.LEFT_DIRECTION);
			player.setDirection(GameContext.LEFT_DIRECTION);
			player.setWalkingL(true);
			break;
		case KeySettings.RUN:
			player.setRunning(true);
			break;
		case KeySettings.SHOT:
			if(!player.isJumping())
				player.setShooting(true);
			break;
		case KeySettings.TURNDOWN:
			if(!player.isDead() && !player.isJumping() && !player.isFalling()){
				player.turnDown();
				player.setLowered(true);
			}
			break;
		default:
			break;
		}
	}

	@Override
	public void setPlayer(CharacterInterface player) {
		this.player = player;

	}
	@Override
	public CharacterInterface getPlayer() {
		return player;

	}

}
